import akka.actor.{Actor, ActorRef, ActorSystem, Props}

/**
 * @program: day0304_3
 * @description: 尽信书，则不如无书
 * @author: CoreDao
 * @create: 2021-03-04 16:46
 * */
//单个actor通信模型
class MyActor extends Actor{
  override def receive: Receive = {
    case msg:String => {
      println(msg + " " + self.path.name)
      println("已读")
    }
    case _:Int =>{
      println("这是个数字"+ " " + self.path.name)
    }
    case _ =>{
      println("no"+ " " + self.path.name)
    }
  }
}


//直接主函数
object ActorTest extends App {
  //ActorSystem类似于聊天室，在这里面用actorRef进行相互之间的通信
  private val system: ActorSystem = ActorSystem("system")

  private val actor: ActorRef = system.actorOf(Props[MyActor], "actor")
  private val actor1: ActorRef = system.actorOf(Props(classOf[MyActor]), "actor1")
  private val actor2: ActorRef = system.actorOf(Props(new MyActor), "actor2")
  //！前边接收消息
  actor ! "你好"
  actor ! 'c'
  actor1 ! 3
  actor2 ! 2

}
